package br.com.puertorico.mecanismos.ui.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.LongConverter;

/**
 * Respons&aacute;vel pela conver&ccedil;&atilde;o de um valor que representa um
 * OID.
 *
 * @author <a href="mailto:daniel.camargo@ufms.br">Daniel Camargo</a>
 * @version $id$
 */
public class IdConverter extends LongConverter {

	/**
	 * {@inheritDoc}
	 */
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
		Object obj = super.getAsObject(arg0, arg1, value);
		if (obj != null) {
			Long valor = (Long) obj;
			if (valor < 1) {
				return null;
			}
		}
		return obj;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		String valor = super.getAsString(arg0, arg1, arg2);
		if (valor.equals("0")) {
			valor = "";
		}
		return valor;
	}
}
